package com.ruoyi.test_tree.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.test_tree.domain.DevicePurpose;
import com.ruoyi.test_tree.service.IDevicePurposeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 设备用途Controller
 * 
 * @author ruoyi
 * @date 2025-08-11
 */
@RestController
@RequestMapping("/test/testTree1")
public class DevicePurposeController extends BaseController
{
    @Autowired
    private IDevicePurposeService devicePurposeService;

    /**
     * 查询设备用途列表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:list')")
    @GetMapping("/list")
    public AjaxResult list(DevicePurpose devicePurpose)
    {
        List<DevicePurpose> list = devicePurposeService.selectDevicePurposeList(devicePurpose);
        return success(list);
    }

    /**
     * 导出设备用途列表
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:export')")
    @Log(title = "设备用途", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevicePurpose devicePurpose)
    {
        List<DevicePurpose> list = devicePurposeService.selectDevicePurposeList(devicePurpose);
        ExcelUtil<DevicePurpose> util = new ExcelUtil<DevicePurpose>(DevicePurpose.class);
        util.exportExcel(response, list, "设备用途数据");
    }

    /**
     * 获取设备用途详细信息
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:query')")
    @GetMapping(value = "/{purposeId}")
    public AjaxResult getInfo(@PathVariable("purposeId") Long purposeId)
    {
        return success(devicePurposeService.selectDevicePurposeByPurposeId(purposeId));
    }

    /**
     * 新增设备用途
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:add')")
    @Log(title = "设备用途", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevicePurpose devicePurpose)
    {
        return toAjax(devicePurposeService.insertDevicePurpose(devicePurpose));
    }

    /**
     * 修改设备用途
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:edit')")
    @Log(title = "设备用途", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevicePurpose devicePurpose)
    {
        return toAjax(devicePurposeService.updateDevicePurpose(devicePurpose));
    }

    /**
     * 删除设备用途
     */
    @PreAuthorize("@ss.hasPermi('test:testTree1:remove')")
    @Log(title = "设备用途", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purposeIds}")
    public AjaxResult remove(@PathVariable Long[] purposeIds)
    {
        return toAjax(devicePurposeService.deleteDevicePurposeByPurposeIds(purposeIds));
    }
}
